﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swcommands;
using SolidWorks.Interop.swconst;
using SolidWorks.Interop.swpublished;

using SwAddinHelpers.Contracts;
using SwAddinHelpers;
using SwAddinHelpers.Base;
using SwAddinHelpers.Attributes;
using SwAddinHelpers.Sinks;

using System.ComponentModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Design;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;

namespace ExternalControls
{
    [ComVisible(true)]
    [ProgId(PROGID)]
    [Export(typeof(IExternalUserControl))]
    [HostedAsTaskpane]
    public partial class TaskPaneControl2 : TaskPaneControlBase, IExternalUserControl
    {
        public const string PROGID = "SwExternalControls.ExternalTaskPaneControl2";

        public dynamic ExternalUserControl
        {
            get { return this; }
        }

        public TaskPaneControl2()
        {
            InitializeComponent();
        }

        protected override void ThrowOnOwnerHostSetter()
        {
            
        }

       

        [SinkMethod(enumEventSink.SW_ActiveDocChangeNotify)]
        private void ActiveDocChangedNotification(object sender, EventArgs e)
        {
            MessageBox.Show("From TaskPaneControl2: ActiveDocChangeNotify fired");
        }


        private void button2_Click(object sender, EventArgs e)
        {
            comboBox1.Items.AddRange((string[])_OwnerHost.OwnerAddin.RetrieveUIHostByProgId("SwExternalControls.ExternalTaskPaneControl1").GetInvokableMethodNames().ToArray());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = _OwnerHost.OwnerAddin.RetrieveUIHostByProgId("SwExternalControls.ExternalTaskPaneControl1").InvokeMethod(comboBox1.Text).ToString();

            //textBox1.Text = _OwnerHost.OwnerAddin.RetrieveUIHostByControlType<TaskPane.TaskPaneHost>(enumHostedControl.DEFAULT_PMP).InvokeMethod("TestMethod2", new object[] { 123, "hello world"}).ToString();
        }

      

    }
}


